home *** CD-ROM | disk | FTP | other *** search
- unit OptGridU;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Grids, DBGrids;
-
- type
- TDBOptGrid = class(TDBGrid)
- protected
- function GetOptWidth: Integer;
- public
- property OptWidth: Integer read GetOptWidth;
- end;
-
- procedure Register;
-
- implementation
-
- function TDBOptGrid.GetOptWidth: Integer;
- var
- Loop: Integer;
- begin
- { Vertical scroll bar }
- Result := GetSystemMetrics(sm_CXVScroll);
- { Left and right borders }
- if BorderStyle = bsSingle then
- Inc(Result, 2 * GetSystemMetrics(sm_CXBorder));
- { Each column, possibly including the indicator }
- for Loop := 0 to Pred(ColCount) do
- Inc(Result, Succ(ColWidths[Loop]));
- { Make sure it fits in parent }
- if Parent is TForm then
- begin
- if Result > TForm(Parent).ClientWidth then
- Result := TForm(Parent).ClientWidth;
- end
- else
- if Result > Parent.Width then
- Result := Parent.Width;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Samples', [TDBOptGrid]);
- end;
-
- end.
-